<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace app\common\controller;

use think\Controller;
use think\Config;
use think\Lang;
use think\Hook;

/**
 * Description of Frontends
 *
 * @author Administrator
 */
load_trait('controller/Jump');

class Frontends extends Controller
{
    use \traits\controller\Jump;
    public $uid;
    public function _initialize()
    {
        $this->uid = isset($_COOKIE['uid']) ? $_COOKIE['uid'] : '';
        $actionname = strtolower($this->request->action());
        $arr = array('login', 'register');
        if (!$this->uid) {
            if (!in_array($actionname, $arr)) {
                $this->error(__('Please login first'), 'user/login');
            }
        } else {
            if (in_array($actionname, $arr)) {
                $url = $this->request->request('url', url('user/index'));
                $this->success('您已经登录', $url);
            }
        }
    }

    protected function loadlang($name)
    {
        Lang::load(APP_PATH . $this->request->module() . '/lang/' . Lang::detect() . '/' . str_replace('.', '/', $name) . '.php');
    }
    //put your code here
}
